package com.resource.project.service.system.service.impl;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.resource.project.common.HrUtils;
import com.resource.project.entity.system.Menu;
import com.resource.project.entity.system.MenuRole;
import com.resource.project.mapper.MenuMapper;
import com.resource.project.mapper.MenuRoleMapper;
import com.resource.project.service.system.service.IMenuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author resource
 * @since 2020-03-14
 */
@Service
public class MenuServiceImpl extends ServiceImpl<MenuMapper, Menu> implements IMenuService {
    @Autowired
    private MenuMapper menuMapper;
    @Autowired
    private MenuRoleMapper menuRoleMapper;

    public List<Menu> getAllMenu(){
        return list();
    }

    public List<Menu> getMenusByHrId() {
//        return menuMapper.getMenusByHrId(35L);
        Long userId = HrUtils.getCurrentHr().getId();
        return menuMapper.getMenusByHrId(userId);
    }

    public List<Menu> menuTree() {
        return menuMapper.menuTree();
    }

    public List<Long> getMenusByRid(Long rid) {
        return null;//menuMapper.getMenusByRid(rid);
    }

    public List<Menu> getAllMenuWithRole(){
        return menuMapper.menuTree();
    }

    public List<Long> getAllMenuByRole(Long id) {
        return menuRoleMapper.selectList(Wrappers.<MenuRole>lambdaQuery().eq(MenuRole::getRid,id)).stream().map(MenuRole::getMid).collect(Collectors.toList());
    }

}
